<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.library.entity.Book" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书馆管理系统 - 编辑图书</title>
    <style>
        body { font-family: Arial, sans-serif; }
        .sidebar { width: 200px; float: left; }
        .content { margin-left: 220px; }
        .menu { list-style-type: none; padding: 0; }
        .menu li { margin-bottom: 10px; }
        .menu li a { display: block; padding: 5px; background-color: #f1f1f1; text-decoration: none; }
        .menu li a:hover { background-color: #ddd; }
        .error { color: red; }
    </style>
</head>
<body>
    <h1>图书馆管理系统 - 编辑图书</h1>
    <div class="sidebar">
        <ul class="menu">
            <li><a href="dashboard.jsp">首页</a></li>
            <li><a href="books">图书管理</a></li>
            <li><a href="addBook.jsp">添加图书</a></li>
            <li><a href="users">用户管理</a></li>
            <li><a href="borrowRecords">借阅记录</a></li>
            <li><a href="../logout">退出登录</a></li>
        </ul>
    </div>
    <div class="content">
        <h2>编辑图书</h2>
        <%
            Book book = (Book) request.getAttribute("book");
            if (book != null) {
        %>
        <form action="editBook" method="post">
            <input type="hidden" name="id" value="<%= book.getId() %>">
            <div>
                <label for="title">书名:</label>
                <input type="text" id="title" name="title" value="<%= book.getTitle() %>" required>
            </div>
            <div>
                <label for="author">作者:</label>
                <input type="text" id="author" name="author" value="<%= book.getAuthor() %>" required>
            </div>
            <div>
                <label for="publisher">出版社:</label>
                <input type="text" id="publisher" name="publisher" value="<%= book.getPublisher() %>" required>
            </div>
            <div>
                <label for="publishDate">出版日期:</label>
                <input type="date" id="publishDate" name="publishDate" 
                    value="<%= book.getPublishDate() != null ? book.getPublishDate().toString().substring(0, 10) : "" %>" required>
            </div>
            <div>
                <label for="status">状态:</label>
                <select id="status" name="status" required>
                    <option value="0" <%= book.getStatus() == 0 ? "selected" : "" %>>可借阅</option>
                    <option value="1" <%= book.getStatus() == 1 ? "selected" : "" %>>已借出</option>
                </select>
            </div>
            <div>
                <label for="location">存放位置:</label>
                <input type="text" id="location" name="location" value="<%= book.getLocation() %>" required>
            </div>
            <div>
                <button type="submit">保存</button>
            </div>
        </form>
        <%
            } else {
        %>
        <p>图书不存在</p>
        <%
            }
        %>
        <% if (request.getAttribute("error") != null) { %>
            <p class="error"><%= request.getAttribute("error") %></p>
        <% } %>
    </div>
</body>
</html>    